package cn.iocoder.yudao.module.reading.controller.app.assignment.vo;

import cn.iocoder.yudao.module.reading.framework.vo.BaseUrlConvertVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * 未完成作业的学生 Response VO
 *
 * @author 芋道源码
 */
@Schema(description = "用户 APP - 未完成作业的学生 Response VO")
@Data
@EqualsAndHashCode(callSuper = false)
public class IncompleteStudentRespVO extends BaseUrlConvertVO {

    @Schema(description = "用户ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Long userId;

    @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小明")
    private String nickname;

    @Schema(description = "用户头像", example = "https://example.com/avatar.jpg")
    private String avatar;

    @Schema(description = "已完成绘本数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Integer completedBooks;

    @Schema(description = "总绘本数", requiredMode = Schema.RequiredMode.REQUIRED, example = "3")
    private Integer totalBooks;

    @Schema(description = "完成进度百分比", requiredMode = Schema.RequiredMode.REQUIRED, example = "33.33")
    private Double progressPercentage;

    @Schema(description = "最后提交时间")
    private LocalDateTime lastSubmitTime;

    @Schema(description = "剩余未完成绘本数", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
    private Integer remainingBooks;

    @Schema(description = "是否已开始作业", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
    private Boolean isStarted;

    @Schema(description = "完成状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "进行中")
    private String status;

    /**
     * 计算完成进度百分比
     */
    public void calculateProgressPercentage() {
        if (totalBooks != null && totalBooks > 0) {
            this.progressPercentage = Math.round((double) completedBooks / totalBooks * 100 * 100.0) / 100.0;
        } else {
            this.progressPercentage = 0.0;
        }
    }

    /**
     * 设置完成状态
     */
    public void setCompletionStatus() {
        if (completedBooks == null || totalBooks == null) {
            this.status = "未知";
            return;
        }

        if (completedBooks.equals(totalBooks)) {
            this.status = "已完成";
        } else if (completedBooks > 0) {
            this.status = "进行中";
        } else {
            this.status = "未开始";
        }
    }

    /**
     * 转换URL字段
     * 将相对路径转换为完整URL
     */
    @Override
    public void convertUrls() {
        this.avatar = convertUrl(this.avatar);
    }
}
